﻿Imports System.IO
Imports System.Threading

Imports Un4seen.Bass
Imports Un4seen.BassWasapi
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
'Imports NAudio
'Imports NAudio.Codecs
Imports NAudio.CoreAudioApi
'Imports NAudio.Dmo
'Imports NAudio.Dsp
'Imports NAudio.FileFormats
'Imports NAudio.Gui
'Imports NAudio.Midi
'Imports NAudio.Mixer
'Imports NAudio.SoundFont
'Imports NAudio.Utils
Imports NAudio.Wave
'Imports NAudio.WindowsMediaFormat

Public Class frmMain

    Private mblnExit As Boolean = False                     'flag to exit app
    Private mlstDevice As List(Of clsSound.stDeviceInfo)    'list of devices
    Private mlstChkDevice As List(Of clsSound.stDeviceInfo)
    Private mobjDevice As clsSound                          'class to manage sound devices

    Private mintDuration As Integer = 0                     'waiting time
    Private mblnAlerted As Boolean = False                  'flag to mark alert
    Private mblnDeviceLost As Boolean = False               'flag to mark when device is lost
    Private mblnIsRunning As Boolean = False                'flag running
    Private mblnFirstRunningInBg As Boolean = False         'flag the fist running in bg
    Private mintChannel As Integer                          'radio channel

    'http://s16.myradiostream.com:6494/
    'http://radio.kigen.co:8000/xrm.opus

    ''' <summary>
    ''' Constructor
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        xInit()

    End Sub


    ''' <summary>
    ''' Init values
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xInit() As Boolean

        xInit = False

        Try
            mobjDevice = New clsSound()
            BassNet.Registration("litiqi@gmail.com", "2X5292916152222")
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)

            'invisible notify icon
            nfiMonitor.Visible = False
            mblnFirstRunningInBg = False

            If My.Settings.blnAutoStart Then

                mblnFirstRunningInBg = True
                xToTray()
                xRun()

            End If

            Return True

        Catch ex As Exception
            clsCommon.fncShowErr("xInit" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Form Load - Load settings
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try

            'load device
            xFillDevices(My.Settings.strDevID)

            'load source
            If My.Settings.blnSrcFromFile Then
                rdFromFile.Checked = True
            Else
                rdFromStream.Checked = True
            End If

            txtFile.Text = My.Settings.strSrcFile
            txtStream.Text = My.Settings.strSrcStream
            txtWebpage.Text = My.Settings.strWebpage
            txtDuration.Value = My.Settings.intDuration
            If My.Settings.blnAutoStart Then chkAutoStart.Checked = True Else chkAutoStart.Checked = False

            txtHost.Text = My.Settings.strSmtpHost
            txtPort.Text = My.Settings.strSmtpPort
            chkSSL.Checked = My.Settings.blnSmtpSSL
            txtLogin.Text = My.Settings.strSmtpLogin
            txtPassword.Text = My.Settings.strSmtpPass

            txtToAddress.Text = My.Settings.strMailTo
            txtSubject.Text = My.Settings.strMailSubject
            txtContent.Text = My.Settings.strMailContent

        Catch ex As Exception
            clsCommon.fncShowErr("frmMain_Load" & vbCrLf & ex.Message)
        End Try

    End Sub


    ''' <summary>
    ''' Refesh list of devices
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        Try
            xFillDevices(My.Settings.strDevID)

        Catch ex As Exception
            clsCommon.fncShowErr("btnRefresh_Click" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Save settings
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            If Not mblnIsRunning Then
                If xSaveSettings() Then clsCommon.fncShowInfo("Settings saved.")
            Else
                If xSaveSettings() Then clsCommon.fncShowInfo("Settings saved. " & vbCrLf & "The monitor is running, if you change the sound source, you need restart monitor to take effects.")
            End If

        Catch ex As Exception
            clsCommon.fncShowErr("btnSave_Click" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Start monitoring
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click, mniStop.Click, mniStart.Click
        Try
            xRun()

        Catch ex As Exception
            Me.Text = "Sound Card Monitor"
            clsCommon.fncShowErr("btnSave_Click" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Run monitor
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xRun() As Boolean

        xRun = False

        Try
            'if monitor is running
            If mblnIsRunning Then
                mniStart.Enabled = True
                mniStop.Enabled = False
                btnRun.Text = "Run"
                Me.Text = "Sound Card Monitor"
                mobjDevice.fncStop()
                Bass.BASS_ChannelStop(mintChannel)
                tmrMonitor.Stop()
                mblnAlerted = False
                mblnIsRunning = False
                xSetStatus(mblnIsRunning)
            Else
                If mblnFirstRunningInBg Then
                    mblnFirstRunningInBg = False
                Else
                    If Not xSaveSettings() Then Exit Function
                End If
                mniStart.Enabled = False
                mniStop.Enabled = True
                btnRun.Text = "St&op"
                Me.Text = "Sound Card Monitor - Running"
                tmrMonitor.Start()
                mblnAlerted = False
                mblnIsRunning = True
                xSetStatus(mblnIsRunning)
            End If

            Return True
        Catch ex As Exception
            clsCommon.fncShowErr("xRun" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Selection changes
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub rdFromFile_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdFromFile.CheckedChanged
        Try
            If rdFromFile.Checked Then
                txtFile.Enabled = True
                btnBrowseFile.Enabled = True
                txtStream.Enabled = False
            Else
                txtFile.Enabled = False
                btnBrowseFile.Enabled = False
                txtStream.Enabled = True
            End If
        Catch ex As Exception
            clsCommon.fncShowErr("rdFromFile_CheckedChanged" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Select media file
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnBrowseFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseFile.Click
        Try
            'If dlgOpenFile.ShowDialog() <> DialogResult.OK Then Exit Sub

            'txtFile.Text = dlgOpenFile.FileName

            Dim objOpenFile As frmBrowseFileDialog

            objOpenFile = New frmBrowseFileDialog()

            objOpenFile.fncShowForm()

            If objOpenFile.FileSelected Then
                txtFile.Text = objOpenFile.FileDir
            End If

        Catch ex As Exception
            clsCommon.fncShowErr("btnBrowseFile_Click" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Close window
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Try
            mblnExit = True
            mobjDevice.fncStop()
            Bass.BASS_ChannelStop(mintChannel)
            Me.Close()
            Environment.Exit(Environment.ExitCode)
        Catch ex As Exception
            clsCommon.fncShowErr("xRestoreWindows" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Minimize to system tray
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub frmMain_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Try
            If Me.WindowState <> FormWindowState.Minimized Then Exit Sub
            xToTray()
        Catch ex As Exception
            clsCommon.fncShowErr("frmMain_Resize" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Prevent close form and minimize to tray
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub frmMain_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Try
            If Not mblnExit Then

                e.Cancel = True
                xToTray()

            End If
        Catch ex As Exception
            clsCommon.fncShowErr("frmMain_FormClosing" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Double click tray -> restore windows
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub nfiMonitor_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles nfiMonitor.MouseDoubleClick
        Try
            xRestoreWindows()
        Catch ex As Exception
            clsCommon.fncShowErr("nfiMonitor_MouseDoubleClick" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Click setting -> restore windows
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub mniSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mniSettings.Click
        Try
            xRestoreWindows()
        Catch ex As Exception
            clsCommon.fncShowErr("mniSettings_Click" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Exit app
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub mniExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mniExit.Click
        Try
            mblnExit = True
            Me.Close()
        Catch ex As Exception
            clsCommon.fncShowErr("mniExit_Click" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Test connection
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
        Try
            Dim intPort As Integer
            Dim objMail As clsEmail
            Dim stEmail As clsEmail.stMailDetail

            'check port
            If Not Integer.TryParse(txtPort.Text.Trim(), intPort) Then
                clsCommon.fncShowWarning("Port must be a number.", txtPort)
                Exit Sub
            End If

            objMail = New clsEmail()
            stEmail = New clsEmail.stMailDetail()

            stEmail.strFromAdress = txtLogin.Text.Trim()
            stEmail.strToAddress = "litiqi@gmail.com"
            stEmail.strSubject = "Test connection"
            stEmail.strBody = "Test connection from sound card monitor."

            stEmail.strSmtpHost = txtHost.Text.Trim()
            stEmail.intSmtpPort = intPort
            stEmail.strSmtpUser = txtLogin.Text.Trim()
            stEmail.strSmtpPass = txtPassword.Text.Trim()

            If objMail.fncSendEmail(stEmail) Then
                clsCommon.fncShowInfo("Successed.")
            Else
                clsCommon.fncShowWarning("Failed. Please check your settings.", txtHost)
            End If

        Catch ex As Exception
            clsCommon.fncShowErr("mniExit_Click" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Fill devices to combobox
    ''' </summary>
    ''' <param name="strSelectedDevice">Device id</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xFillDevices(ByVal strSelectedDevice As String) As Boolean

        xFillDevices = False

        Try
            mlstDevice = mobjDevice.GetAllDevices

            'clear before using
            cboDevices.Items.Clear()

            'add no device
            cboDevices.Items.Add(New clsItem("( No device )", ""))
            cboDevices.SelectedIndex = 0

            'or fill devices
            For i As Integer = 0 To mlstDevice.Count - 1

                cboDevices.Items.Add(New clsItem(mlstDevice(i).strDevName, mlstDevice(i).strDevID))

                'set selected
                If mlstDevice(i).strDevID = strSelectedDevice Then cboDevices.SelectedIndex = i + 1

            Next

            Return True

        Catch ex As Exception
            clsCommon.fncShowErr("xFillDevices" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Save settings
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xSaveSettings() As Boolean

        xSaveSettings = False

        Try
            'device
            My.Settings.strDevID = CType(cboDevices.SelectedItem, clsItem).Value.ToString()

            'source
            My.Settings.blnSrcFromFile = False
            If rdFromFile.Checked Then My.Settings.blnSrcFromFile = True
            My.Settings.strSrcFile = txtFile.Text.Trim()
            My.Settings.strSrcStream = txtStream.Text.Trim()

            'others
            My.Settings.strWebpage = txtWebpage.Text.Trim()
            My.Settings.intDuration = CInt(txtDuration.Value)
            My.Settings.blnAutoStart = chkAutoStart.Checked

            'smtp
            My.Settings.strSmtpHost = txtHost.Text.Trim()
            My.Settings.strSmtpPort = txtPort.Text.Trim()
            My.Settings.blnSmtpSSL = chkSSL.Checked
            My.Settings.strSmtpLogin = txtLogin.Text.Trim()
            My.Settings.strSmtpPass = txtPassword.Text.Trim()

            'mail
            My.Settings.strMailFrom = txtLogin.Text.Trim()
            My.Settings.strMailTo = txtToAddress.Text.Trim()
            My.Settings.strMailSubject = txtSubject.Text.Trim()
            My.Settings.strMailContent = txtContent.Text.Trim()

            'set auto startup 
            If chkAutoStart.Checked Then
                clsCommon.fncRunAtStartup(clsConst.gcstrApplicationName, Application.ExecutablePath)
            Else
                clsCommon.fncRemoveValue(clsConst.gcstrApplicationName)
            End If

            My.Settings.Save()

            Return True

        Catch ex As Exception
            clsCommon.fncShowErr("xSaveSettings" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Minimize windows to system trays
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xToTray() As Boolean

        xToTray = False

        Try
            Me.WindowState = FormWindowState.Minimized
            Me.Visible = False
            nfiMonitor.Visible = True
            nfiMonitor.ShowBalloonTip(2000)
            Return True

        Catch ex As Exception
            clsCommon.fncShowErr("xToTray" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Restore windows to init state
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xRestoreWindows() As Boolean

        xRestoreWindows = False

        Try
            nfiMonitor.Visible = False
            Me.Visible = True
            Me.WindowState = FormWindowState.Normal
            Me.BringToFront()
            Return True

        Catch ex As Exception
            clsCommon.fncShowErr("xRestoreWindows" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Monitor sound card
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub tmrMonitor_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMonitor.Tick
        Try
            'check if device is not avaiable
            'If Not xIsDeviceAvaiable(My.Settings.strDevID) Then
            If Not xIsPlayingSound() Then
                mblnDeviceLost = True

                'raise alert
                If Not mblnAlerted Then
                    tmrWait.Start()
                    'Dim objAlertThread As Thread
                    'objAlertThread = New Thread(AddressOf tmrWait_Tick)
                    'objAlertThread.Start()
                    mblnAlerted = True
                End If

            Else
                'if device was lost and now be back, open webpage
                If mblnDeviceLost Then
                    Dim frmWeb As frmBrowser

                    'reset value
                    mblnDeviceLost = False
                    mblnAlerted = False

                    'stop the sound
                    mobjDevice.fncStop()
                    Bass.BASS_ChannelStop(mintChannel)

                    'open webpage
                    frmWeb = New frmBrowser()
                    frmWeb.fncShowForm(My.Settings.strWebpage)

                End If
            End If

        Catch ex As Exception
            clsCommon.fncShowErr("tmrMonitor_Tick" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' After 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub tmrWait_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrWait.Tick
        'Private Sub tmrWait_Tick()
        Try
            'mintDuration += 1

            'If mintDuration = My.Settings.intDuration Then
            'stop timer
            'mintDuration = 0
            tmrWait.Stop()

            'play background sound
            xPlaySound()

            'and send email until success
            Dim objSendMailThread As Thread
            objSendMailThread = New Thread(AddressOf xSendEmail)
            objSendMailThread.Start()

            'End If

        Catch ex As Exception
            clsCommon.fncShowErr("tmrWait_Tick" & vbCrLf & ex.Message)
        End Try
    End Sub


    ''' <summary>
    ''' Check if device is avaiable
    ''' </summary>
    ''' <param name="strDevID">device id</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xIsDeviceAvaiable(ByVal strDevID As String) As Boolean

        xIsDeviceAvaiable = False

        Try

            ''if there is no device, return false
            'If mobjDevice.GetNumberOfSoundCards <= 0 Then Return False

            ''else check device id
            'mlstChkDevice = mobjDevice.GetAllDevices

            'For i As Integer = 0 To mlstChkDevice.Count - 1
            '    If strDevID = mlstChkDevice(i).strDevID Then Return True
            'Next

        Catch ex As Exception
            clsCommon.fncShowErr("xIsDeviceAvaiable" & vbCrLf & ex.Message)
        End Try

    End Function


    Private Function xIsPlayingSound() As Boolean

        xIsPlayingSound = True

        Try
            Dim intNumberOfAudio As Integer = mobjDevice.fncNumActiveSession()
            'Dim intB As Double = mobjDevice.fncCurActivePeak()

            mintDuration += 1

            'if main audio is play (hasn't lost)
            If Not mblnDeviceLost Then

                If intNumberOfAudio >= 1 Then
                    mintDuration = 0
                    Return True
                End If

                'if there is no sound
                If intNumberOfAudio = 0 And mintDuration = My.Settings.intDuration Then
                    mintDuration = 0
                    Return False
                End If

            Else
                If intNumberOfAudio >= 2 And mintDuration < 2 Then Return False

                'if there is 2 sound at least 2s
                If intNumberOfAudio >= 2 And mintDuration = 2 Then
                    'mintDuration = 0
                    Return True
                Else
                    mintDuration = 0
                    Return False
                End If
            End If

        Catch ex As Exception
            clsCommon.fncShowErr("xIsPlayingSound" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Send email
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xSendEmail() As Boolean

        xSendEmail = False

        Try
            Dim stEmail As clsEmail.stMailDetail
            Dim objMail As clsEmail
            Dim blnStop As Boolean = False

            stEmail = New clsEmail.stMailDetail()
            objMail = New clsEmail()

            stEmail.strFromAdress = My.Settings.strMailFrom
            stEmail.strToAddress = My.Settings.strMailTo
            stEmail.strSubject = My.Settings.strMailSubject
            stEmail.strBody = My.Settings.strMailContent

            stEmail.strSmtpHost = My.Settings.strSmtpHost
            stEmail.intSmtpPort = My.Settings.strSmtpPort
            stEmail.strSmtpUser = My.Settings.strSmtpLogin
            stEmail.strSmtpPass = My.Settings.strSmtpPass

            Do Until blnStop

                'try to send
                If objMail.fncSendEmail(stEmail) Then blnStop = True

                'if monitor stoped
                If Not mblnIsRunning Then blnStop = True

                'send fail, try again after 60s
                If Not blnStop Then Thread.Sleep(60000)

            Loop

            Return True
        Catch ex As Exception
            clsCommon.fncShowErr("xSendEmail" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Play background sound
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xPlaySound() As Boolean

        xPlaySound = False

        Try
            If My.Settings.blnSrcFromFile Then
                If Not File.Exists(My.Settings.strSrcFile) Then
                    clsCommon.fncShowErr("Sound file does not exist.")
                    Exit Function
                Else
                    mobjDevice.fncPlay(My.Settings.strSrcFile)
                End If
            Else
                Try
                    mintChannel = Bass.BASS_StreamCreateURL(My.Settings.strSrcStream, 0, BASSFlag.BASS_DEFAULT, Nothing, IntPtr.Zero)
                    Bass.BASS_ChannelPlay(mintChannel, True)

                Catch ex As Exception
                    Dim objErr As BASSError = Bass.BASS_ErrorGetCode()
                    clsCommon.fncShowErr("xPlaySound" & vbCrLf & objErr.ToString())
                End Try
            End If

            Return True
        Catch ex As Exception
            clsCommon.fncShowErr("xPlaySound" & vbCrLf & ex.Message)
        End Try

    End Function


    ''' <summary>
    ''' Set indicator
    ''' </summary>
    ''' <param name="blnIsRunning">status, true if monitor is running</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function xSetStatus(blnIsRunning As Boolean) As Boolean

        xSetStatus = False

        Try
            If blnIsRunning Then

                lblStatus.Text = "Monitor is running ..."
                mniStatus.Text = "Monitor is running ..."
                pnStatus.BackColor = Color.Lime
                mniStatus.Image = My.Resources.circle_green

            Else

                lblStatus.Text = "Monitor stopped"
                mniStatus.Text = "Monitor stopped"
                pnStatus.BackColor = Color.Red
                mniStatus.Image = My.Resources.circle_red

            End If

            Return True
        Catch ex As Exception
            clsCommon.fncShowErr("xSetStatus" & vbCrLf & ex.Message)
        End Try

    End Function


End Class
